﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Primitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:utils="clr-namespace:BlogApp.WP8.Utils"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    x:Class="BlogApp.WP8.View.CategoryPage"
    mc:Ignorable="d"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    DataContext="{Binding CategoryViewModel, Source={StaticResource Locator}}"
    >

    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource ResourceKey="PhoneFontSizeNormal"/>
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource ResourceKey="PhoneForegroundBrush"/>
    </phone:PhoneApplicationPage.Foreground>
    <phone:PhoneApplicationPage.Background>
        <StaticResource ResourceKey="BackgroundBrush"/>
    </phone:PhoneApplicationPage.Background>
    
    <shell:SystemTray.ProgressIndicator>
        <shell:ProgressIndicator IsIndeterminate="{Binding IsLoading}" 
                                 IsVisible="{Binding IsLoading}" />
    </shell:SystemTray.ProgressIndicator>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" ForegroundColor="{StaticResource AppBarForegroundColor}" BackgroundColor="{StaticResource AccentColor}"  Mode="Default">
            <shell:ApplicationBarIconButton IconUri="/Assets/appbar.search.png" Text="[search]" x:Name="AppBarIconButtonSearch" Click="AppBarIconButtonSearch_Click" />
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>


    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="{StaticResource BackgroundBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Margin="12,17,0,32">
            <TextBlock Text="{Binding LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource AccentBrush}"/>
            <TextBlock Text="{Binding SelectedCategory.Title}" Margin="7,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Foreground="{StaticResource AccentBrush}"/>
        </StackPanel>

        <phone:LongListSelector toolkit:TiltEffect.IsTiltEnabled="True" ItemsSource="{Binding PostsForCategory.Posts}" Style="{StaticResource LongListSelectorStyle}" Grid.Row="1" Margin="0">
            <i:Interaction.Behaviors>
                <utils:IncrementalLoadingBehavior LoadCommand="{Binding CategoryViewModel.LoadMoreItems, Source={StaticResource Locator}}" />
            </i:Interaction.Behaviors>
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" Tap="OnPostTapped" Margin="24,0,12,12">
                        <TextBlock Text="{Binding TitlePlain, Converter={StaticResource UnicodeToTextConverter}}" Style="{StaticResource PhoneTextNormalStyle}" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="{StaticResource AccentBrush}" TextWrapping="Wrap" TextTrimming="WordEllipsis" Margin="0"/>
                        <TextBlock Text="{Binding Excerpt, Converter={StaticResource UnicodeToTextConverter}}" Style="{StaticResource PhoneTextNormalStyle}" FontSize="{StaticResource PhoneFontSizeSmall}" TextTrimming="WordEllipsis" TextWrapping="Wrap" Foreground="{StaticResource TeaserTextBrush}"  Margin="0"/>
                    </StackPanel>
                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector>
    </Grid>

</phone:PhoneApplicationPage>